package com.s666.demo.controller;

import com.s666.demo.model.dto.ZikuDTO;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author lijin
 */
@RestController
@RequestMapping("/rest_test")
@Slf4j
public class RestTestController extends BaseController {

    /**
     * get 请求
     * /test/get?name=3
     * @param name
     * @return
     */
    @RequestMapping("/get")
    public String get(@RequestParam(value = "name", required = false) String name) {
        return "get的值为" + name;
    }

    @Data
    private class Model {
        private String name;
        private String city;
    }
    /**
     * post请求
     * /test/post?name=张三&city=城市
     * @param model
     * @return
     */
    @RequestMapping(value = "/post", method = {RequestMethod.GET,RequestMethod.POST})
    public String post(Model model) {
        return model.toString();
    }

    /**
     * post json 请求
     * /test/post_json
     * @param zikuDTO
     * @return
     */
    @RequestMapping(value = "/post_json", method = {RequestMethod.GET,RequestMethod.POST})
    public String postJson(@RequestBody ZikuDTO zikuDTO) {
        return zikuDTO.toString();
    }
}

